#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define FILE_MOVIE 0
#define FILE_AUDIO 1
#define FILE_PICTURE 2

#define UPNP_VIDEO "object.item.videoItem.movie"
#define UPNP_AUDIO "object.item.audioItem.musicTrack"
#define UPNP_PICTURE "object.item.imageItem.photo"

#define PROTOCOL_MP4 "http-get:*:video/mp4:DLNA.ORG_PN=AVC_MP4_BL_CIF15_AAC_520;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01500000000000000000000000000000"

#define PROTOCOL_AVI "http-get:*:video/avi:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01500000000000000000000000000000"
#define PROTOCOL_WMV "http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVMED_BASE"
#define PROTOCOL_MP3 "http-get:*:audio/mpeg:DLNA.ORG_PN=MP3"
#define PROTOCOL_JPG "http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_SM"

#define PROTOCOL_PNG "http-get:*:image/png:DLNA.ORG_PN=PNG_LRG"


#define PROTOCOL_PNG_SM		"http-get:*:image/png:DLNA.ORG_PN=PNG_SM"
#define PROTOCOL_PNG_MED	"http-get:*:image/png:DLNA.ORG_PN=PNG_MED"
#define PROTOCOL_PNG_LRG	"http-get:*:image/png:DLNA.ORG_PN=PNG_LRG"

#define PROTOCOL_JPG_SM		"http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_SM"
#define PROTOCOL_JPG_MED	"http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED"
#define PROTOCOL_JPG_LRG	"http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG"


#define PROTOCOL_3GP_AVC	"http-get:*:video/3gpp:DLNA.ORG_PN=AVC_3GPP_BL_QCIF15_AAC"
#define PROTOCOL_3GP_MP4V	"http-get:*:video/3gpp:DLNA.ORG_PN=MPEG4_P2_3GPP_SP_L0B_AAC"

#define MPEG_AUDIO_PACKET 1
#define MPEG_VIDEO_PACKET 0

unsigned int getIntFrom4Byte(char* input);
unsigned int getIntFromByte(char* input,int size);

unsigned int getIntFrom4Byte_R(char* input);
unsigned int getIntFromByte_R(char* input, int size);

int getFileTitle(char* filePath, char* title, char* ext);
int getStringFromBuffer(char* input, char* output, int size);

int ConvertDuration(int duration,char* d);


unsigned char* readChars(int size,FILE* fp);
long GetFileLength(FILE* fp);

int dellocateMeta(struct Meta* meta);






typedef struct Meta{

	char* Container;


	char* title;
	char* author;

	char *upnpClass;

	int Frequency;
	int ResolutionX;
	int ResolutionY;
	int Duration;
	int Bitrate;

	int FrameRate;


	int layer;
	long fileSize;

	char* CodecBrand;
	char* ProtocolInfo;
	char* AUD_CODEC;
	char* VID_CODEC;

}MedaData;